// import { list, add, del, update } from '@/api/crud/index';
import {
  setStore,
  getStore,
} from "@/utils/store";
import { ref } from "vue";

export const option = ref({
  size: "small",
  border: true,
  viewBtn: true,
  searchMenuPosition: 'right',
  viewBtnText:'详情',
  searchClearable: true,
  column: [
    {
      label: "姓名",
      prop: "name",
      span: 14,
      row: true,
      search: true,
    },
    {
      label: "手机号",
      prop: "phone",
      span: 14,
      row: true,
      search: true,
    },
    {
      label: "账号",
      prop: "account",
      span: 14,
      row: true,
    },
    {
      label: "创建时间",
      prop: "createTime",
      type: "date",
      format: "YYYY-MM-DD hh:mm:ss",
      span: 14,
      row: true,
    },
  ],
});
export const getPageScope = (current) => {
  const scope = {
    start: 0,
    end: 0,
  };
  scope.start = (current - 1) * 10;
  scope.end = current * 10 - 1;
  return scope;
};

export const setStoreCache = async (data, page) => {
  const cache = await setStore({
    name: "cacheList",
    content: data,
  });
  const res = await setStore({
    name: "cachePage",
    content: page.value,
  });
  const { tableData, pageCache } = getStoreCache();
  if (tableData && pageCache) {
    return true;
  } else {
    return false;
  }
};

export const getStoreCache = () => {
  const tableData = getStore({
    name: "cacheList",
  })
  const pageCache = getStore({
    name: "cachePage",
  });
  return {
    tableData:tableData?.sort((a, b) => a.id - b.id),
    pageCache,
  };
};

export const setStorePage = async (page) => {
  const res = await setStore({
    name: "cachePage",
    content: page.value,
  });
  return res;
};

export const getStorePage = () => {
  return getStore({
    name: "cachePage",
  });
};
